<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{$Assets}layui/css/layui.css">
    <style type="text/css">
.layui-table-body{
    overflow: hidden;
}
    </style>
</head>
<body>
{include file="public/header" /}



<div class="layui-btn-group demoTable" style="margin-left: 15px;">
    <button class="layui-btn" data-type="v_adduser">添加管理员</button>
    <button class="layui-btn layui-btn-danger" data-type="delxz">删除选中</button>
</div>
<div style="width: 98%;margin:0 auto;">
<table class="layui-table" lay-data="{ url:'masterall', page:true,limit:{$config_limit},limits:{$config_limits}, id:'user'}" lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'id', width:100, sort: true,}">ID</th>
        <th lay-data="{field:'master', width:130}">名称</th>
        <th lay-data="{field:'type',width:130}">类型</th>
        <th lay-data="{field:'addtime',width:180}">添加时间</th>
        <th lay-data="{field:'logintime',width:180}">最近登陆</th>
        <th lay-data=""></th>
        <!--<th lay-data="{field:'ChangePass', width:120}">/th>-->
        
        <th lay-data="{width:200, align:'center', toolbar: '#barDemo'}"></th>
    </tr>
    </thead>
</table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<script src="{$Assets}layui/layui.js?t=1515376178709"></script>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
  var table = layui.table,
      form = layui.form,
      layer = layui.layer,
      layedit = layui.layedit,
      laydate = layui.laydate;
        //
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });

        //
  form.on('submit(demo1)', function(data){
    
    var adddata=JSON.stringify(data.field);


                  $.ajax({
                        type:"POST",
                        url: "addmaster",
                        data:{data:adddata},
                        dataType:"json",

                        success:function(datas){
                          
                          
                            if(datas=='1'){
                                layer.msg('添加成功!');
                                
                            }else if(datas=='99'){
                                layer.msg('添加异常!');
                                return false;
                                
                            }else{
                                layer.msg('添加异常!');
                                
                            }

                            setTimeout(function(){  //  setTimeout2000
                                    self.location='/index.php/admin/user/master.html';
                                },1000);


                        }
                    });


    return false;
  });

  form.on('submit(edituser)', function(data){
    
    var adddata=JSON.stringify(data.field);

                    $.ajax({
                        type:"POST",
                        url: "editmaster",
                        data:{data:adddata},
                        dataType:"json",

                        success:function(datas){
                          
                          
                            if(datas=='1'){
                                layer.msg('编辑成功!');
                                setTimeout(function(){  //  setTimeout2000
                                    self.location='/index.php/admin/user/master.html';
                                },500);
                            }else if(datas=='2'){
                                layer.msg('编辑异常!');
                                setTimeout(function(){  //  setTimeout2000
                                    self.location='/index.php/admin/user/master.html';
                                },1000);
                            }
                        }
                    });



    return false;
  });



        //
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                
            } else if(obj.event === 'del'){
                layer.confirm('', function(index){

                    $.ajax({
                        type:"POST",
                        url: "delmaster",
                        data:{id:data.id},
                        dataType:"json",

                        success:function(datas){
                            //alert(sdata);
                            //layer.msg(datas);

                            if(datas=='1'){
                                layer.msg('删除成功!');
                                setTimeout(function(){  //  setTimeout2000
                                    self.location='/index.php/admin/user/master';
                                },500);
                            }else{
                                layer.msg('删除异常!');
                                setTimeout(function(){  //  setTimeout2000
                                    self.location='/index.php/admin/user/master';
                                },1000);
                            }
                        }
                    });

                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){



              layer.open({
                type: 1
                ,title: false //
                ,closeBtn: false
                ,area: '500px;'
                ,shade: 0.8
                ,id: 'LAY_layuipro' //id
                ,closeBtn:2
                ,btnAlign: 'c'
                ,moveType: 1 //
                ,content: $('#edituser')
                
              });
              $("#edit_id").attr("value",data.id);
          

             



            }
        });

        var $ = layui.$, active = {
            delxz: function(){ //
                var checkStatus = table.checkStatus('user')
                    ,data = checkStatus.data;
                var deldatas=JSON.stringify(data);
                
                
                $.ajax({
                    type:"POST",
                    url: "delmasters",
                    data:{num:deldatas},
                    dataType:"json",
                    success:function(datas){
                        //layer.close(index);
                        //alert(datas);
                        layer.msg('删除成功');
                        
                        setTimeout(function(){  //  setTimeout2000
                            window.location.reload();//
                        },1000);
                    }
                });
            },
            
            v_adduser:function(){
              layer.open({
                type: 1
                ,title: false //
                ,closeBtn: false
                ,area: '500px;'
                ,shade: 0.8
                ,id: 'LAY_layuipro' //id
                ,closeBtn:2
                ,btnAlign: 'c'
                ,moveType: 1 //
                ,content: $('#adduser')
                
              });
            }

        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>








<div  id="adduser" style="display: none;">
    <div style="padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;height: 305px;">
    <fieldset class="layui-elem-field" style="padding:20px 20px 55px;margin-bottom: 30px">
            <legend>添加管理员</legend>

    <form class="layui-form" action="" style="margin-left: -55px;">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
              <input type="text" name="master" lay-verify="required"  autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
              <input type="password" name="pword" lay-verify="required"  autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">类型</label>
          <div class="layui-input-inline" style="color: #000;">
            <select name="ini" lay-verify="required">
              <option value="">请选择</option>
              <option value="1">超级管理员</option>
              <option value="2">管理员</option>
            </select>
          </div>
        </div>

      <div class="layui-form-item" style="margin-top: 10px;">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
      
    </form>
    </fieldset>
    </div>
</div>



<div  id="edituser" style="display: none;">
    <div style="padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;height: 260px;">
    <fieldset class="layui-elem-field" style="padding:20px 20px 55px;margin-bottom: 30px">
            <legend>编辑管理员</legend>

    <form class="layui-form" action="">
        <input type="hidden" name="id" value="" id="edit_id" class="layui-input">

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
              <input type="text" name="pword"  autocomplete="off" placeholder="为空则不修改" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">类型</label>
          <div class="layui-input-inline" style="color: #000;">
            <select name="ini">
              <option value=""></option>

              {volist name="admin_level" id="level"}
                    <option value="{$level.level}">{$level.name}</option>
              {/volist}
             
            </select>
          </div>
        </div>

      <div class="layui-form-item" style="margin-top: 10px;">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit="" lay-filter="edituser">提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
      
    </form>
    </fieldset>
    </div>
</div>


{include file="public/footer"/}
</body>
</html>
